<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.SupplierDAO"%>
<%@page import="db.Supplier"%>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	request.setCharacterEncoding("utf-8");
	
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	SupplierDAO supplierDao = (SupplierDAO)ctx.getBean("SupplierDAO");
	
	Integer teamId = (Integer)session.getAttribute("tid");
	
	String sid_str = request.getParameter("sid");
	String name = request.getParameter("name");
	String person = request.getParameter("person");
	String phone = request.getParameter("phone");
	String remark = request.getParameter("remark");
	
	if(sid_str != null && !"".equals(sid_str)){
		try{
			Integer sid_int = Integer.parseInt(sid_str);
			Supplier supplier = supplierDao.findById(sid_int);
			supplier.setDate(new Date());
			supplier.setIsDelete(0);
			supplier.setName(name);
			supplier.setPerson(person);
			supplier.setPhone(phone);
			supplier.setTeamId(teamId);
			if(remark == null) remark = "";
			supplier.setRemark(remark);
			
			supplierDao.attachDirty(supplier);
			
			request.setAttribute("info","success");
			
			pageContext.forward("/vm/supinfo/mod_supinfo.vm");
		}catch(Exception e){
			request.setAttribute("info","error");
			pageContext.forward("/vm/supinfo/mod_supinfo.vm");
		}
	}else{
		request.setAttribute("info","error");
		pageContext.forward("/vm/supinfo/mod_supinfo.vm");
	}
	
%>